<template>
	<view class="page">
		<view class="list">
			<view class="item" >
				<text class="key">姓名</text>
				<text class="value">{{name}}</text>
			</view>
			<view class="item">
				<text class="key">生日</text>
				<text class="value">{{birthday}}</text>
			</view>
			<view class="item">
				<text class="key">性别</text>
				<text class="value">{{sex}}</text>
			</view>
			<view class="item">
				<text class="key">民族</text>
				<text class="value">{{ethnic}}</text>
			</view>
			<view class="item">
				<text class="key">政治面貌</text>
				<text class="value">{{identity}}</text>
			</view>
			<view class="item">
				<text class="key">所在组织</text>
				<text class="value">{{organization}}</text>
			</view>
			<view class="item">
				<text class="key">从事岗位</text>
				<text class="value">{{job}}</text>
			</view>
			<view class="item">
				<text class="key">当前职级</text>
				<text class="value">{{role}}</text>
			</view>
			<view class="item">
				<text class="key">联系号码</text>
				<text class="value">{{account}}</text>
			</view>
			<view class="item">
				<text class="key">电子邮件</text>
				<text class="value">{{email}}</text>
			</view>
			<view class="item">
				<text class="key">微信号</text>
				<text class="value">{{vx}}</text>
			</view>
			<view class="item">
				<text class="key">其他联系方式</text>
				<text class="value">{{contact}}</text>
			</view>
			<view class="item">
				<text class="key">入职日期</text>
				<text class="value">{{createTime}}</text>
			</view>
			<view class="item" @tap="editDesc">
				<text class="key">
					自我介绍
				</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{description}}</text>
			</view>
			<view class="item" @tap="editMotto">
				<text class="key">座右铭</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{motto}}</text>
			</view>
		</view>
		<uni-popup ref="popupDesc" type="dialog">
			<uni-popup-dialog mode="input" title="自我介绍" :value="description" placeholder="请简单介绍一下自己吧,不超过30字!" @confirm="finishDesc">
			</uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="popupMotto" type="dialog">
			<uni-popup-dialog mode="input" title="座右铭" :value="motto" placeholder="请简要概述自己的座右铭,不超过20字!" @confirm="finishMotto">
			</uni-popup-dialog>
		</uni-popup>
		
	</view>
</template>
<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
	import uniIcons from '@/components/uni-icons/uni-icons.vue';
	
	export default {
		components: {
			uniPopup,
			uniPopupMessage,
			uniPopupDialog,
			uniIcons
		},
		data() {
			return {
				name:'',
				birthday:'',
				sex:'',
				ethnic:'',
				identity:'',
				organization:'',
				job:'',
				role:'',
				account:'',
				email:'',
				vx:'',
				contact:'',
				createTime:'',
				description:'',
				motto:''
			}
		},
		onLoad: function() {
			let that = this;
			that.ajax(that.url.getuserinfo, "POST", null, function(resp) {
				let data = resp.data;
				let user = data.userinfo.user;
				let roles = data.userinfo.roles;
				let message = "未填写";
				if(!user.isRegistration || user.name==null || user.name.length<=0){
					that.name = "新员工"
				}else{
					that.name = user.name;
				}
				if(!user.isRegistration || user.birthday==null || user.birthday.length<=0){
					that.birthday = message
				}else{
					that.birthday = that.formatDataTime(user.birthday)
				}
				if(!user.isRegistration || user.sex==null || user.sex.length<=0){
					that.sex = message
				}else{
					that.sex = user.sex.name
				}
				if(!user.isRegistration || user.ethnic==null || user.ethnic.length<=0){
					that.ethnic = message
				}else{
					that.ethnic = user.ethnic.name
				}
				if(!user.isRegistration || user.identity==null || user.identity.length<=0){
					that.identity = message
				}else{
					that.identity = user.identity.name
				}
				if(user.organization==null || user.organization.length<=0){
					that.organization = message
				}else{
					that.organization = user.organization.name
				}
				if(user.job==null || user.job.length<=0){
					that.job = message
				}else{
					that.job = user.job.name
				}
				if(user.account==null || user.account.length<=0){
					that.account = message
				}else{
					that.account = user.account
				}
				if(user.email==null || user.email.length<=0){
					that.email = message
				}else{
					that.email = user.email
				}
				if(!user.isRegistration || user.vx==null || user.vx.length<=0){
					that.vx = message
				}else{
					that.vx = user.vx
				}
				if(!user.isRegistration || user.contact==null || user.contact.length<=0){
					that.contact = message
				}else{
					that.contact = user.contact
				}
				if(!user.isRegistration || user.createTime==null || user.createTime.length<=0){
					that.createTime = message
				}else{
					that.createTime = that.formatDataTime(user.createTime)
				}
				if(user.description==null || user.description.length<=0){
					that.description = message
				}else{
					that.description = user.description
				}
				if(user.motto==null || user.motto.length<=0){
					that.motto = message
				}else{
					that.motto = user.motto
				}
				that.role = roles[0].name;
			});
		},
		methods: {
			editDesc:function(){
				this.$refs.popupDesc.open();
			},
			finishDesc:function(done,value){
				let that = this;
				if(value.length>=30){
					uni.showToast({
						title:"字数太多",
						icon:'error'
					})
				}else{
					uni.showModal({
						title: '提示',
						content: '是否确认修改自我介绍',
						success: function(e) {
							if (e.confirm) {
								that.ajax(that.url.updateDescription,'POST',{
									description:value
								},function(resp){
									let data = resp.data;
									that.description = data.result;
								})
								done()
							}
						}
					});
				}
			},
			editMotto:function(){
				this.$refs.popupMotto.open();
			},
			finishMotto:function(done,value){
				let that = this;
				if(value.length>=20){
					uni.showToast({
						title:"字数太多",
						icon:'error'
					})
				}else{
					uni.showModal({
						title: '提示',
						content: '是否确认修改座右铭',
						success: function(e) {
							if (e.confirm) {
								that.ajax(that.url.updateMotto,'POST',{
									motto:value
								},function(resp){
									let data = resp.data;
									that.motto = data.result;
								})
								done()
							}
						}
					});
				}
			}
		}
	}
</script>

<style lang="less">
	@import url("user_info.less");
</style>
